// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class RuleNode extends cc.Component {


    // LIFE-CYCLE CALLBACKS:
    @property(cc.Node)
    nextNode:cc.Node = null;
    @property(cc.Node)
    lastNode:cc.Node = null;
    index = 0;
    ruleArr = []
    
    onEnable() {
        // this.updateRule(this.index);
    }
    

    btnCallback(target,data){
        if(data == "next"){
            this.index ++;
            this.updateRule(this.index)
        }else if(data == "last"){
            this.index --; 
            this.updateRule(this.index)
        }else if(data == "back"){
            this.node.active = false;
        }
    }
    updateRule(index){
        if(this.index == this.ruleArr.length -1){
            this.nextNode.active = false;
        }else{
            this.nextNode.active = true;
        }
        if(this.index == 0){
            this.lastNode.active = false;
        }else{
            this.lastNode.active = true;
        }


        let rulePageNode = this.node.getChildByName("rule");
        this.ruleArr = rulePageNode.children;
        for(let i = 0;i<this.ruleArr.length;i++){
            if(i == index){
                this.ruleArr[i].active = true;
            }else{
                this.ruleArr[i].active = false;
            }
        }
    }

    // update (dt) {}
}
